package cn.itcast.bos.service.base.impl;

import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.domain.base.TakeTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.base.FixedAreaRepository;
import cn.itcast.bos.domain.base.FixedArea;
import cn.itcast.bos.service.base.FixedAreaService;

import java.util.List;

@Transactional
@Service
public class FixedAreaServiceImpl implements FixedAreaService {

	@Autowired
	private FixedAreaRepository fixedAreaRepository;
	@Override
	public void save(FixedArea fixedArea) {
		fixedAreaRepository.save(fixedArea);
	}
	
	@Override
	public Page<FixedArea> find(Specification<FixedArea> spec, Pageable pageable) {
		return fixedAreaRepository.findAll(spec, pageable);
	}

	@Override
	public void update(String id, String takeTimeId, String courierId) {
		FixedArea fixedarea = fixedAreaRepository.findOne(id);
		Courier courier = new Courier();
		courier.setId(Integer.parseInt(courierId));
		fixedarea.getCouriers().add(courier);
		TakeTime takeTime = new TakeTime();
		takeTime.setId(Integer.parseInt(courierId));
		courier.setTakeTime(takeTime);
	}

	@Override
	public List<FixedArea> findAll() {
		return fixedAreaRepository.findAll();
	}

}
